#include "bcmc_cnckernel.h"
#include "cnckernel.h"

namespace cnc {

	namespace base {
		BCMC_CNCKernel::BCMC_CNCKernel() : bcm::Identifier<bcm::Component>("cnckrnl", "CNC Kernel"),
			bcm::Identifier<BCMI_KernelSetup>("krnlsetup", "Kernel Setup"),
			bcm::Identifier<BCMI_TaskControl>("taskctl", "Task Control"),
			krnlSetup_(CNCKernel::instance().getKernelSetup()),
			coopTask_(CNCKernel::instance().getCooperativeTask())
		{
		}

		// Kernel Setup
		void BCMC_CNCKernel::addTask(CooperativeTask *backgroundTask)
		{
			krnlSetup_->addTask(backgroundTask);
		}

		void BCMC_CNCKernel::addMode(OperationModeID modeID, CooperativeMode *operationMode)
		{
			if (modeID != OPMODE_END)
				krnlSetup_->addMode(modeID, operationMode);
		}

		void BCMC_CNCKernel::selectMode(OperationModeID modeID)
		{
			if (modeID != OPMODE_END)
				krnlSetup_->selectMode(modeID);
		}

		OperationModeID BCMC_CNCKernel::getMode()
		{
			return krnlSetup_->getMode();
		}

		// Task Control (Cooperative Task)
		bool BCMC_CNCKernel::start()
		{
			return coopTask_->start();
		}

		bool BCMC_CNCKernel::execute()
		{
			return coopTask_->execute();
		}

		bool BCMC_CNCKernel::stop()
		{
			return coopTask_->stop();
		}

		extern "C" bcm::Component *getComponent(bcm::GetComponentResult *result)
		{
			*result = bcm::GC_OK;
			return &BCMC_CNCKernel::instance();
		}

	} // namespace base

} // namespace cnc
